package com.itchen.service.impl;

import com.itchen.controller.Result;
import com.itchen.dao.BookDao;
import com.itchen.pojo.Book;
import com.itchen.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author げっしょく
 * @date 2021/9/16
 */
@Service
public class BookServiceImpl implements BookService {

    @Autowired
    private BookDao bookDao;

    public Result save(Book book) {
        int save = bookDao.save(book);
        if (save > 0) {
            return new Result(true);
        }
        return new Result(false);
    }

    public Result update(Book book) {
        int update = bookDao.update(book);
        if (update > 0) {
            return new Result(true);
        }
        return new Result(false);
    }

    public Result delete(Integer id) {
        int delete = bookDao.delete(id);
        if (delete > 0) {
            return new Result(true);
        }
        return new Result(false);
    }

    public Result getById(Integer id) {
        Book byId = bookDao.getById(id);
        boolean flag = byId != null ? true : false;
        return new Result(byId, flag);
    }

    public Result getAll() {
        List<Book> all = bookDao.getAll();
        boolean flag = all != null ? true : false;
        return new Result(all, flag);
    }
}
